package com.cqie.hospitalescort.controller;

import com.cqie.hospitalescort.DTO.HospitalDTO;
import com.cqie.hospitalescort.VO.HospitalInfoVO;
import com.cqie.hospitalescort.entity.HospitalInfo;
import com.cqie.hospitalescort.model.Result;
import com.cqie.hospitalescort.service.HospitalInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author gdy
 * @since 2025-02-24
 */
@RestController
@RequestMapping("/hospitalInfo")
@Api(value = "医院管理",tags = {"医院管理"})
public class HospitalInfoController extends BaseController {

    @Autowired
    private HospitalInfoService hospitalInfoService;

    @GetMapping("/list")
    @ApiOperation(value = "医院列表")
    public Result<List<HospitalInfo>> list() {
        return response(hospitalInfoService.getList());
    }

    @GetMapping("/detail")
    @ApiOperation(value = "医院详情")
    public Result<HospitalInfoVO> getHospitalDetail(@RequestParam Long hospitalId) {
        return response(hospitalInfoService.getHospitalDetail(hospitalId));
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增、修改医院信息")
    @PreAuthorize(value = "hasRole('ROLE_ADMIN')")
    public Result<Void> save(@ModelAttribute @Validated HospitalDTO dto, @RequestParam("pictures") List<MultipartFile> fileList) {
        hospitalInfoService.saveHospital(dto, fileList);
        return response();
    }

    @DeleteMapping("/delete")
    @ApiOperation(value = "删除医院")
    @PreAuthorize(value = "hasRole('ROLE_ADMIN')")
    public Result<Void> delete(@RequestParam Long id) {
        hospitalInfoService.delete(id);
        return response();
    }

}
